<include file='Common:header' />
<link rel="stylesheet" type="text/css" media="all" href="__PUBLIC__/sldate/daterangepicker-bs3.css" />
<script type="text/javascript" src="__PUBLIC__/sldate/moment.js"></script>
<script type="text/javascript" src="__PUBLIC__/sldate/daterangepicker.js"></script>
<script src="__PUBLIC__/My97DatePicker/WdatePicker.js"></script>
<!-- /section:basics/navbar.layout -->
<div class="main-container" id="main-container">

    <!-- #section:basics/sidebar -->

    <include file='Common:left' />
    <!-- /section:basics/sidebar -->
    <div class="main-content">
        <div class="main-content-inner">
            <div class="page-content">

                <!--主题-->
                <div class="page-header">
                    <h1>
                        您当前操作
                        <small>
                            <i class="ace-icon fa fa-angle-double-right"></i>
                            下发报表
                        </small>
                    </h1>
                </div>





                <div class="row">
                    <div class="col-xs-12">
                        <div>
                            <form class="form-horizontal" name="form1" id="form1" method="post" action="{:U('send_table_run')}">
                                <div class="form-group">
                                    <label class="col-sm-5 control-label no-padding-right" for="form-field-1">选择报表：  </label>
                                    <div class="col-sm-3">
                                        <select name="tableid" id="tableid">
                                            <option value="">--选择报表--</option>
                                            <foreach name="type" item="v">
                                                <option value="{$v.id}">{$v.title}</option>
                                            </foreach>
                                        </select>

                                    </div>
                                </div>
                                <div class="space-4"></div>

                                <div class="form-group">
                                    <label class="col-sm-5 control-label no-padding-right" for="form-field-1">报表年份：  </label>
                                    <div class="col-sm-3">
                                            <select id="year" name="year">
                                                <option value="0">请选择年份</option>
                                                <volist name="year" id="v">
                                                    <option value="{$v}">{$v}</option>   
                                                </volist>
                                            </select>
                                    </div>

                                </div>
                                <div class="space-4"></div>

                                <div class="form-group">
                                    <label class="col-sm-5 control-label no-padding-right" for="form-field-1">报表季度：  </label>
                                    <div class="col-sm-3">
                                        
                                        <select id="quarter" name="quarter">
                                            <option value="0">请选择季度</option>
                                            <option value="1">1</option>
                                            <option value="2">2</option>
                                            <option value="3">3</option>
                                            <option value="4">4</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="space-4"></div>

                                <div class="form-group">
                                    <label class="col-sm-5 control-label no-padding-right" for="form-field-1">报表有效期：  </label>
                                    <div class="col-sm-3">
                                        <input type="text" style="display: inline-block;" class="Wdate" id="endtime" name="endtime" onFocus="WdatePicker({lang:'zh-cn',dateFmt:'yyyy-MM-dd HH:mm:ss'})" placeholder="请点击选择有效期" />
                                    </div>
                                </div>
                                <div class="space-4"></div>

                                <table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">


                                    <tr>
                                        <td height="30"  style="border-bottom:#CCCCCC solid 1px; line-height:25px; background-color:#F4F8FB">
                                            <label>
                                                <input type="checkbox" class="ace ace-checkbox-2"  id='chkAll' onclick='CheckAll(this.form)' value="全选"/>
                                                <span class="lbl"> 企业全选</span>
                                            </label>
                                            <label style="margin: 0 19%;">
                                                <input style="height: 25px;" id="company_text" type="text" placeholder="请输入查询的公司标题" value="">
                                                <button type="button" id="ajax_c">搜索</button>
                                            </label>
                                            <label style="float: right;">按分类筛选企业: &nbsp;&nbsp;&nbsp;&nbsp;
                                                    <select id="company_type">
                                                        <option value="">---选择筛选企业分类---</option>
                                                        <option value="1">港区规模以上贸易业</option>
                                                        <option value="2">港区物流专业市场</option>
                                                        <option value="3">临港规模以上工业</option>
                                                        <option value="4">港区运输企业</option>
                                                        <option value="5">港区仓储配送企业</option>
                                                        <option value="6">其他</option>
                                                    </select>
                                                &nbsp;&nbsp;
                                            </label>
                                        </td>


                                    </tr>
                                    <tr>


                                            <td class="company_info" height="30" style="padding-left:70px;border-bottom:#E7EBF8 dashed 1px; color:#666666">

                                                <volist name="company" id="vo">
                                                    <label class="thopen">
                                                        <input name="sendid[]" class="ace ace-checkbox-2 checkbox-child" type="checkbox"  id="{$vo.comid}" value="{$vo.comid}"  />
                                                    <span class="lbl" style="margin-right:10px;">{$vo.name}</span>
                                                    </label>
                                                </volist>

                                            </td>


                                    </tr>

                                </table>



                                <div class="clearfix form-actions">
                                    <div class="col-md-offset-5 col-md-9">
                                        <button class="btn btn-info" type="submit">
                                            <i class="ace-icon fa fa-check bigger-110"></i>
                                            下发
                                        </button>

                                        &nbsp; &nbsp; &nbsp;
                                        <button class="btn" type="reset">
                                            <i class="ace-icon fa fa-undo bigger-110"></i>
                                            重置
                                        </button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>

                <include file='Common:header_nav' />

            </div><!-- /.page-content -->
        </div>
    </div><!-- /.main-content -->


    <script>
        var app = '__APP__';
        function CheckAll(form){
            for (var i=0;i<form.elements.length;i++){
                var e = form.elements[i];
                if (e.Name != 'chkAll'&&e.disabled==false)
                    e.checked = form.chkAll.checked;
            }
        }

        $(function(){
            $("#ajax_c").click(function () {
                var text = $('#company_text').val();
                $.ajax({
                    type : 'post',
                    data : {text:text},
                    dataType : 'json',
                    url : app+'/Admin/table/company_ajax',
                    success : function(res){
                        $('.company_info').empty();
                        var htmls = '';
                        if (res != ''){
                            $.each(res,function (item,value) {
                                htmls +='<label class="thopen">';
                                htmls +='<input name="sendid[]" class="ace ace-checkbox-2 checkbox-child" type="checkbox"  id="'+value.comid+'" value="'+value.comid+'" />';
                                htmls +='<span class="lbl" style="margin-right:10px;">'+value.name+'</span>';
                                htmls +='</label>';
                            })
                            console.log(htmls);
                        }else {
                            htmls = '<p style="text-align: center">暂无企业</p>'
                        }

                        $('.company_info').append(htmls);
                    }
                });
            });

            $('#company_type').change(function () {
                if($(this).val() != ''){
                    $.ajax({
                        type : 'post',
                        data : {id:$(this).val()},
                        dataType : 'json',
                        url : app+'/Admin/table/type_ajax',
                        success : function(res){
                            $('.company_info').empty();
                            var htmls = '';
                            if (res != ''){
                                $.each(res,function (item,value) {
                                    htmls +='<label class="thopen">';
                                    htmls +='<input name="sendid[]" class="ace ace-checkbox-2 checkbox-child" type="checkbox"  id="'+value.comid+'" value="'+value.comid+'" />';
                                    htmls +='<span class="lbl" style="margin-right:10px;">'+value.name+'</span>';
                                    htmls +='</label>';
                                })
                                console.log(htmls);
                            }else {
                                htmls = '<p style="text-align: center">暂无企业</p>'
                            }

                            $('.company_info').append(htmls);
                        }
                    });
                }
            });

            $('#form1').ajaxForm({
                beforeSubmit: checkForm, // 此方法主要是提交前执行的方法，根据需要设置
                success: complete, // 这是提交后的方法
                dataType: 'json'
            });

            function checkForm(){

                if( '' == $.trim($('#tableid option:selected').val())){
                    layer.alert('请选择报表', {icon: 6}, function(index){
                        layer.close(index);
                        $('#tableid').focus();
                    });
                    return false;
                }


                if( '0' == $.trim($('#year option:selected').val())){
                    layer.alert('请选择报表年份', {icon: 6}, function(index){
                        layer.close(index);
                        $('#year').focus();
                    });
                    return false;
                }
                //正则判断年份格式是否正确
                var reDateTime = /^(?:19|20)[0-9][0-9]$/;
                
                var isDateTime = reDateTime.test($.trim($('#year option:selected').val()));
                if (isDateTime == false){
                    layer.alert('报表年份格式有误', {icon: 6}, function(index){
                        layer.close(index);
                        $('#year').focus();
                    });
                    return false;
                }


                if('0' == $.trim($('#quarter option:selected').val())){
                    layer.alert('请选择报表季度', {icon: 6}, function(index){
                        layer.close(index);
                        $('#quarter').focus();
                    });
                    return false;
                }
                var quarter1 = $.trim($('#quarter option:selected').val());
                var arr = new Array("1","2","3","4");
                var isquarter = $.inArray(quarter1,arr);
                if(isquarter == -1){
                    layer.alert('报表季度格式有误', {icon: 6}, function(index){
                        layer.close(index);
                        $('#quarter').focus();
                    });
                    return false;
                }

                if(''== $.trim($('#endtime').val())){
                    layer.alert('请选择报表有效期时间', {icon: 6}, function(index){
                        layer.close(index);
                        $('#endtime').focus();
                    });
                    return false;
                }
                if($("input:checkbox[name='sendid[]']:checked").length == 0){
                    layer.alert('请至少选中一个下发企业', {icon: 6}, function(index){
                        layer.close(index);
                        $('.company_info').focus();
                    });
                    return false;
                }

            }
            function complete(data){
                if(data.status==1){
                    layer.alert(data.info, {icon: 6}, function(index){
                        layer.close(index);
                        window.location.href=data.url;
                    });
                }else{
                    layer.alert(data.info, {icon: 6}, function(index){
                        layer.close(index);
                    });
                    return false;
                }
            }

        });
    </script>
    <include file='Common:footer' />

</div><!-- /.main-container -->
</body>
</html>
